package com.zyg.apart.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyg.apart.mapper.FlatsMapper;
import com.zyg.apart.model.Flatplay;
import com.zyg.apart.model.Flats;
import com.zyg.apart.service.FlatsService;
import com.zyg.apart.util.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class FlatsServiceImpl implements FlatsService {
	@Autowired
	private FlatsMapper flatsMapper;


	@Override
	public PageInfo<Map<String, Object>> getAll(Integer currentPage) {
		PageHelper.startPage(currentPage, Const.pageSize);
		List<Map<String,Object>> list = flatsMapper.getAll();
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

	@Override
	public Flats getFlatById(Integer id) {
		return flatsMapper.getFlatById(id);
	}

	@Override
	public List<Flats> getAllName() {
		return flatsMapper.getAllName();
	}

	@Override
	public int delFlatById(Integer id) {
		return flatsMapper.delFlatById(id);
	}

	@Override
	public int editFlats(Flats flats) {
		flats.setH_updateTime(new Date());
		return flatsMapper.editFlats(flats);
	}

	@Override
	public int addFlats(Flats flats) {
		flats.setH_addTime(new Date());
		return flatsMapper.addFlats(flats);
	}
}
